package concurrent;

import java.util.ArrayList;

/**
 * @author 26029
 * @date 2025/4/23
 * @description
 */
public class LearnSynchronized {
    public static void main(String[] args) {
        SynchronizedObject instance1 = new SynchronizedObject();
        SynchronizedObject instance2 = new SynchronizedObject();
        Thread t1 = new Thread(instance1);
        Thread t2 = new Thread(instance2);
        t1.start();
        t2.start();
    }
}

//
class SynchronizedObject implements Runnable {
    @Override
    public void run() {
        method();
    }

    public static synchronized void method() {
        System.out.println("线程" + Thread.currentThread().getName() + "开始");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程" + Thread.currentThread().getName() + "结束");
    }
}